package com.flash.InventoryManagement.service.impl;

import com.flash.InventoryManagement.entity.CashAccrualStock;
import com.flash.InventoryManagement.entity.CashStock;
import com.flash.InventoryManagement.entity.SecurityStock;
import com.flash.InventoryManagement.mapper.CashAccrualStockMapper;
import com.flash.InventoryManagement.service.CashAccrualStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/23
 */
@Service
public class CashAccrualStockServiceImpl implements CashAccrualStockService {
    @Autowired
    CashAccrualStockMapper cashAccrualStockMapper;


    @Override
    public int countCashAccrualStock() {
        return cashAccrualStockMapper.countCashAccrualStock();
    }

    @Override
    public List<CashAccrualStock> selectCashAccrualStock(CashAccrualStock cashAccrualStock, int page, int limit) {
        HashMap map = new HashMap();
        map.put("strWhere", buildWhere(cashAccrualStock));
        map.put("page",(page-1)*limit+1);
        map.put("limit",limit*page);
        return cashAccrualStockMapper.selectCashAccrualStock(map);
    }

    @Override
    public int insertCashAccrualStock(CashAccrualStock cashAccrualStock) {
        return cashAccrualStockMapper.insertCashAccrualStock(cashAccrualStock);
    }

    @Override
    public int updateCashAccrualStock(CashAccrualStock cashAccrualStock) {
        return cashAccrualStockMapper.updateCashAccrualStock(cashAccrualStock);
    }

    @Override
    public int deleteCashAccrualStock(CashAccrualStock cashAccrualStock) {
        return cashAccrualStockMapper.deleteCashAccrualStock(cashAccrualStock);
    }

    public String buildWhere (CashAccrualStock cashAccrualStock) {
        StringBuffer strWhere = new StringBuffer();
        if (cashAccrualStock.getCashAccrualStockId()!=null && !cashAccrualStock.getCashAccrualStockId().equals("")){
            strWhere.append(" and cashAccrualStockId like '%" + cashAccrualStock.getCashAccrualStockId() +"%'" );
        }
        if (cashAccrualStock.getDateAccrualStock()!=null && !cashAccrualStock.getDateAccrualStock().equals("")){
            strWhere.append(" and dateAccrualStock like '%" + cashAccrualStock.getDateAccrualStock() +"%'" );
        }
        return strWhere.toString();
    }


}
